﻿<?php
	include '../inc/conn.php';
	include '../sendmail.php';
	
	session_start();
	extract($_POST);
	extract($_GET);
	$pagestr = end(explode("/",$_SERVER['PHP_SELF']));
	unset($_POST,$_GET);
	
	if (isset($act))
	{
		if ($act == 'add' && isset($_SESSION['logname']))
		{
			if (empty($biosDate) || empty($biosDir) || empty($biosReason)){
				echo "<script>alert('BIOS切割日期或BIOS监视目录不能为空');window.location='$pagestr';</script>";
				die("BIOS切割日期或BIOS监视目录不能为空");
			}
			$biosDir=trim(strtoupper($biosDir));
			$biosDate=trim(strtoupper($biosDate));
			$biosReason=trim(strtoupper($biosReason));

			if(isset($isOpen))
				$isOpen=1;
			else
				$isOpen=0;

			$db = new mysql();
			$sql="INSERT INTO `bios_monitor` (`BIOS_DIR`, `BIOS_DATE`, `BIOS_Reason`,`status`) values('${biosDir}', '${biosDate}', '${biosReason}', $isOpen)";
			$db->query($sql);
			$param = array(
				'aSync'=>'Yes',
				'title'=>"新增【${biosDir}】监视内容通知",
				'msg'=>"<b>监视目录：</b><font color='blue'>$biosDir</font></br>
						<b>监视日期：</b><font color='blue'>$biosDate</font></br>
						<b>监视原因：</b><font color='blue'>$biosReason</font></br></br>监视内容添加完成，请<b>机种负责人</b>注意投产确认状况！",
				'to'=>'TE'
			);
			doAsyncMail($param);
			$db->close();
			echo "<script>alert('数据添加成功!');window.opener.location.reload();window.location.href='$pagestr'</script>";
		}
		
		if ($act == 'change' && isset($_SESSION['logname']))
		{
			if (empty($biosDate) || empty($biosDir) || empty($biosReason)){
				echo "<script>alert('BIOS切割日期或BIOS监视目录不能为空');window.location='$pagestr';</script>";
				die("BIOS切割日期或BIOS监视目录不能为空");
			}

			$biosDir=trim(strtoupper($biosDir));
			$biosDate=trim(strtoupper($biosDate));
			$biosReason=trim(strtoupper($biosReason));

			if(isset($isOpen))
				$isOpen=1;
			else{
				$isOpen=0;
				if($closeReason=='N/A')
					$closeReason='未写关闭原因';
			}

			$db = new mysql();
			$table = "bios_monitor";
			$condition = "ID=${id}";
			$mod_content="`BIOS_DIR`='${biosDir}', `BIOS_DATE`='${biosDate}', `BIOS_Reason`='${biosReason}',`status`=$isOpen, `Close_Reason`='${closeReason}'";
			$db->update($table, $mod_content, $condition);
			$db->close();
			echo "<script>alert('内容修改完成!');window.location.href='$pagestr';</script>";
			
		}
	}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">-->
<link rel="stylesheet" href="/css/bootstrap.min.css">
<script type="text/javascript" src="/js/jquery.min.js"></script>
<script type="text/javascript" src="/js/jquery-migrate.min.js"></script>
<script type="text/javascript" src="/xhEditor/xheditor.min.js"></script>
<script type="text/javascript" src="/xhEditor/xheditor_lang/zh-cn.js"></script>
<script type="text/javascript" src="/js/bootstrap.min.js"></script>
<script>
	$(function(){
		$("#ADDDIV").hide();
		$("#ADDSSID").click(function(){
			$("#ADDDIV").toggle();
		});
		
		$("#addbtn").click(function(){
			if ($("#biosDate").val() == ""){
				alert("BIOS切割日期没有填写！");
				return false;
			}

			if ($("#biosDir").val() == ""){
				alert("BIOS监视目录没有填写！");
				return false;
			}			

			if ($("#biosReason").val() == ""){
				alert("更改原因没有填写！");
				return false;
			}
		});

	});
</script>
<title>新增BIOS监视项目</title>
</head>
<body class="background">
<div class="container-fluid white-background pagecontent">
<?
	if(isset($_SESSION['logname'])){
		if ($pagename=="changeitem"){
			echo "<label>操作项次：</label><a id='ADDDUTY' href='biosmon.php'> <span class=\"glyphicon glyphicon-backward\"></span>返回</a>";
		}else{
			echo "<label>操作项次：</label><a id='ADDSSID' href='#'><span class=\"glyphicon glyphicon-plus\"></span>添加</a> | <a href='../doBiosMon.php'> {<span class=\"glyphicon glyphicon-search\"></span>人工查}</a> | <a href='../doBiosMon.php?mail=1'><font color='red'>【<span class=\"glyphicon glyphicon-envelope\"></span>人工邮】</font></a>";
		}
	}
	echo "<div id='ADDDIV'>\n";
	echo "<form action='$pagestr?act=add' method='post'>\n";
	echo "	<div>\n";
	echo "	<b><font color='blue' size='3'>添加内容：</font></b><br />\n";
	echo "		<b>BIOS目录：</b><input name='biosDir' id='biosDir'><br>\n";
	echo "		<b>切割日期：</b><input name='biosDate' id='biosDate'><br>\n";
	echo "		<b>导入原因：</b><input name='biosReason' id='biosReason'><br>\n";	
	echo "		<b>状态开？：</b><input type='checkbox' name='isOpen' value='1' />\n";
	echo "	</div>\n";
	echo "	<div>\n<br><input class='btn btn-success btn-primary' name='submit' value='提交' type='submit' id='addbtn'>\n<input class='btn btn-danger' name='reset' value='重写' type='reset'>\n</div>\n";
	echo "</form>\n";
	echo "</div>\n";

	// change item page
	if ($pagename=="changeitem"){
		$db = new mysql();
		$sql="select * from bios_monitor where ID=$id";
		$db->query($sql);
		$num = $db->db_num_rows();
		$row = $db->fetch_assoc();
		echo "\n<form action='$pagestr?act=change&id=${row['ID']}' method='post'>\n";
		echo "	<div>\n";
		echo "	<b><font color='red' size='3'>修改内容：</font></b><br />\n";
		echo "		<b>BIOS目录：</b><input name='biosDir' id='biosDir' value='${row['BIOS_DIR']}'><br>";
		echo "		<b>切割日期：</b><input name='biosDate' id='biosDate' value='${row['BIOS_DATE']}'><br>";
		echo "		<b>导入原因：</b><input name='biosReason' id='biosReason' value='${row['BIOS_Reason']}'><br>";
		if($row['status']==1){
			echo "		<b>状态开？：</b><input type='checkbox' name='isOpen' value='1' checked='checked' />";
		}else{
			echo "		<b>状态开？：</b><input type='checkbox' name='isOpen' value='1' />";
		}
		echo "<br>		<b>关闭原因：</b><input name='closeReason' id='closeReason' value='${row['Close_Reason']}'><br>";
		echo "	</div>\n";
		echo "	<div>\n<br><input class='btn btn-success btn-primary' name='submit' value='提交' type='submit' id='addbtn'>\n";
		echo "  <input class='btn btn-danger' name='reset' value='重写' type='reset'>\n</div>\n";
		echo "</form>\n";
		$db->close();
	}else{
		$db = new mysql();
		if(isset($sortby)){
			switch($sortby){
				case "su":
					$db->query("select * from bios_monitor order by add_date asc");
					break;
				case "sid":
					$db->query("select * from bios_monitor order by add_date asc");
					break;
			}
		}else{
			$db->query("select * from bios_monitor order by add_date desc");
		}

		$num = $db->db_num_rows();
		echo "<table border=0 cellpadding=0 class='table table-striped'>";
		echo "<tr class='success'><th>Item</th><th><a href='$pagestr?sortby=su'>BIOS目录</a></th><th><a href='$pagestr?sortby=sid'>切割日期</a></th><th>导入原因</th><th>监控状态</th><th>关闭原因</th><th>添加记录时间</th><th>更新记录时间</th><th>操作</th></tr>";
		for($i=0; $i<$num; $i++){
			$row = $db->fetch_assoc();
			$item = $i + 1;
			echo "<tr>";
			echo "<td>$item</td>";
			if(substr($row['add_date'],0,10)==date("Y-m-d")){
				echo "<td><font color='blue'>${row['BIOS_DIR']}</font></td>";
				echo "<td><font color='blue'>${row['BIOS_DATE']}</font></td>";
			}else{
				echo "<td>${row['BIOS_DIR']}</td>";
				echo "<td>${row['BIOS_DATE']}</td>";				
			}
			echo "<td>${row['BIOS_Reason']}</td>";	
			if($row['status']==1)
				echo "<td><font color='red'>打开</font></td>";
			else
				echo "<td>关闭</td>";
			echo "<td>${row['Close_Reason']}</td>";
			echo "<td>${row['add_date']}</td>";
			echo "<td>${row['up_date']}</td>";
			if(isset($_SESSION['logname'])){
				echo "<td><a href='$pagestr?pagename=changeitem&id=${row['ID']}'><span class=\"glyphicon glyphicon-edit\"></span></a></td>";
			}else{
				echo "<td>#</td>";
			}
			echo "</tr>\n";
		}
		echo "</table>";
		$db->close();
	}
?>
</div>
</body>
</html>
